package com.ruihang.generalibrary.ui.util;

import android.view.View;
import android.view.ViewGroup;

import com.jiongbull.jlog.JLog;
import com.ruihang.generalibrary.ui.widget.OnSizeChangeListener;

/**
 * Created by Ly on 2016/12/9.
 */
public class CustomSizeChangeL16_9 implements OnSizeChangeListener {
    @Override
    public void onSizeChanged(View view, int w, int h, int oldw, int oldh) {
        if(w<=0){
            return;
        }
        float wf=w;
        JLog.e("w:"+w+"  h:"+h+"  ow:"+oldw+"  oh:"+oldh);
        if(Math.abs(16f / 9 - wf / h)>0.003){
            JLog.e("lp:"+view.getLayoutParams());
            ViewGroup.LayoutParams lp=view.getLayoutParams();
            JLog.e("lp w:"+lp.width+" h:"+lp.height);
            lp.width=w;
            lp.height= (int) (w*9f/16);
            view.setLayoutParams(lp);
        }
    }
}
